home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Writeswell Jr. 1.0.2 Master
/
Writeswell Jr. Source
/
FontMenu.c
< prev
next >
Wrap
Text File
|
1992-10-28
|
8KB
|
354 lines
/* FontMenu.c
* Handle font and style menus in Writeswell Jr.
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
*
* 19 May 92 Mike Crawford
*/
#include <EPPC.h>
#include <AppleEvents.h>
#include <AEObjects.h>
#include <Script.h>
#include "AERegistry.h"
#include "WordServices.h"
#include "TestBed.h"
#include "TBConstants.h"
#include "Gripe.h"
#include "AppEvents.h"
#include "TBGlobals.h"
#include "FontMenu.h"
#include "OutlineButton.h"
static Style gStyleTable[] = { 0, bold, italic, underline, outline, shadow, condense, extend };
static short gPointSizeTable[] = { 9, 10, 12, 14, 18, 24, 48, 72 };
Boolean DoFontMenu( short theItem )
{
TEHandle textH;
TextStyle styleRec;
MenuHandle fontMenu;
short fontNum;
Str255 fontName;
if ( !gDocWindow )
return true;
textH = (TEHandle)GetWRefCon( gDocWindow );
fontMenu = GetMHandle( kFontMenuID );
if ( !fontMenu )
return false;
GetItem( fontMenu, theItem, fontName );
GetFNum( fontName, &fontNum );
/* Set TE to use the new font */
styleRec.tsFont = fontNum;
TESetStyle( doFont, &styleRec, true, textH );
gDocDirty = true;
return true;
}
Boolean DoStyleMenu( short theItem )
{
TEHandle textH;
if ( theItem == kStMOtherPoint ){
CustomSize();
return true;
}
gDocDirty = true;
if ( theItem < kStMDash ){
SetStyle( theItem );
return true;
}
SetSize( theItem );
return true;
}
void CustomSize( void )
{
TextStyle styleRec;
short fontAscent;
short lineHeight;
TEHandle textH;
DialogPtr custDlg;
short item;
Str255 textStr;
short kind;
Handle h;
Rect r;
long num;
if ( !gDocWindow )
return;
textH = (TEHandle)GetWRefCon( gDocWindow );
custDlg = GetNewDialog( kCustomSizeID, (Ptr)NULL, (WindowPtr)-1 );
if ( !custDlg )
return;
/* Get the current size */
TEGetStyle( (*textH)->selStart, &styleRec, &lineHeight, &fontAscent, textH );
NumToString( (long)fontAscent, textStr );
GetDItem( custDlg, kCSEntryField, &kind, &h, &r );
SetIText( h, textStr );
TESetSelect( 0L, 32000L, ((DialogPeek)custDlg)->textH );
/* Set up a user proc to draw the default outline */
GetDItem( custDlg, kCSDefUser, &kind, &h, &r );
SetDItem( custDlg, kCSDefUser, kind, (Handle)OutlineButton, &r );
do {
ModalDialog( (ProcPtr)NULL, &item );
} while ( item != kCSCancel && item != kCSOK );
if ( item == kCSCancel ){
DisposDialog( custDlg );
return;
}
GetDItem( custDlg, kCSEntryField, &kind, &h, &r );
GetIText( h, textStr );
DisposDialog( custDlg );
StringToNum( textStr, &num );
/* Set TE to use the new style */
styleRec.tsSize = (short)num;
TESetStyle( doSize, &styleRec, true, textH );
gDocDirty = true; /* Note that it's not dirty if we canceled */
return;
}
void SetStyle( short theItem )
{
TextStyle styleRec;
TEHandle textH;
if ( !gDocWindow )
return;
textH = (TEHandle)GetWRefCon( gDocWindow );
/* Set TE to use the new style */
styleRec.tsFace = gStyleTable[ theItem - 1 ];
TESetStyle( doFace, &styleRec, true, textH );
return;
}
void SetSize( short theItem )
{
TextStyle styleRec;
TEHandle textH;
if ( !gDocWindow )
return;
textH = (TEHandle)GetWRefCon( gDocWindow );
theItem -= kStM9Point;
styleRec.tsSize = gPointSizeTable[ theItem ];
TESetStyle( doSize, &styleRec, true, textH );
return;
}
void InitStyleMenu( void )
{
MenuHandle styleMenu;
short i;
styleMenu = (MenuHandle)GetResource( 'MENU', kStyleMenuID );
if ( !styleMenu ){
Gripe( "\pcannot get Style Menu Handle" );
return;
}
for ( i = kStMBold; i < kStMDash; i++ ){
SetItemStyle( styleMenu, i, gStyleTable[ i - 1 ] );
}
return;
}
void FixMenuMarks( void )
{
TextStyle styleRec;
TEHandle textH;
MenuHandle fileMenu;
MenuHandle fontMenu;
MenuHandle styleMenu;
MenuHandle editMenu;
short numItems;
short i;
short fontNum;
short itemSize;
short lineHeight;
short fontAscent;
Str255 fontName;
Str255 itemName;
short mode;
Boolean continuous;
fileMenu = (MenuHandle)GetResource( 'MENU', kFileMenuID );
if ( !fileMenu )
return;
editMenu = (MenuHandle)GetResource( 'MENU', kEditMenuID );
if ( !editMenu )
return;
fontMenu = (MenuHandle)GetResource( 'MENU', kFontMenuID );
if ( !fontMenu )
return;
styleMenu = (MenuHandle)GetResource( 'MENU', kStyleMenuID );
if ( !styleMenu )
return;
DisableItem( editMenu, kEMUndo );
if ( !gDocWindow ){
EnableItem( fileMenu, kFMNew );
EnableItem( fileMenu, kFMOpen );
DisableItem( fileMenu, kFMClose );
DisableItem( fileMenu, kFMSave );
DisableItem( fileMenu, kFMSaveAs );
DisableItem( fileMenu, kFMPageSetup );
DisableItem( fileMenu, kFMPrint );
#ifdef NEVER
/* STUB Do this differently. Don't want to redraw menu bar while mouse is down */
DisableItem( fontMenu, 0 ); /* Disable the entire font menu */
DisableItem( styleMenu, 0 ); /* Disable the entire style menu */
DrawMenuBar();
#endif
return;
}
SetPort( gDocWindow );
DisableItem( fileMenu, kFMNew );
DisableItem( fileMenu, kFMOpen );
EnableItem( fileMenu, kFMClose );
EnableItem( fileMenu, kFMSave );
EnableItem( fileMenu, kFMSaveAs );
EnableItem( fileMenu, kFMPageSetup );
EnableItem( fileMenu, kFMPrint );
#ifdef NEVER
/* STUB Do this differently. Don't want to redraw menu bar while mouse is down */
EnableItem( fontMenu, 0 ); /* Enable the entire font menu */
EnableItem( styleMenu, 0 ); /* Enable the entire style menu */
#endif
textH = (TEHandle)GetWRefCon( gDocWindow );
/* Get the current font */
#ifdef NEVER
TEGetStyle( (*textH)->selStart, &styleRec, &lineHeight, &fontAscent, textH );
#endif
styleRec.tsFont = 0;
styleRec.tsSize = 0;
styleRec.tsFace = 0;
mode = doFont + doFace + doSize;
/* BUG BUG BUG TEContinousStyle does not appear to work as advertised */
continuous = TEContinuousStyle( &mode, &styleRec, textH );
if ( mode & doFont ){
fontNum = styleRec.tsFont;
if ( fontNum == applFont )
fontNum = 3 /*GetAppFont()*/; /* Otherwise Geneva shows up as 1 */
GetFontName( fontNum, fontName );
}else{
fontName[ 0 ] = '\0';
}
numItems = CountMItems( fontMenu );
for ( i = 1; i <= numItems; i++ ){
GetItem( fontMenu, i, itemName );
if ( PStrCmp( itemName, fontName ) ){
CheckItem( fontMenu, i, true );
} else {
CheckItem( fontMenu, i, false );
}
}
/* Show the real font sizes */
for ( i = 0; i < kStMDash2 - kStM9Point; i++ ){
itemSize = gPointSizeTable[ i ];
if ( RealFont( fontNum, itemSize ) ){
SetItemStyle( styleMenu, i + kStM9Point, outline );
}else{
SetItemStyle( styleMenu, i + kStM9Point, 0 );
}
if ( mode & doSize && itemSize == styleRec.tsSize ){ /* 1.0b2 MDC was fontAscent */
CheckItem( styleMenu, i + kStM9Point, true );
} else {
CheckItem( styleMenu, i + kStM9Point, false );
}
}
/* If the styles are the same, check them all, otherwise check none */
for ( i = kStMPlain; i <= kStMExtend; i++ ){
if ( mode & doFace ){
if ( gStyleTable[ i - 1 ] & styleRec.tsFace )
CheckItem( styleMenu, i, true );
}else{
CheckItem( styleMenu, i, false );
}
}
return;
}